package com.junbao.message.infrastructure.page;

import java.util.Date;

/**
 * 数据查询对象
 * @author yilin
 *
 */
@SuppressWarnings("all")
public class DataQuereyCondition{
	
	private final static int DEFULT_PAGENUM = 1;//默认从第一页开始查询 
	
	private final static int DEFULT_PAGESIZE = 200;//默认一次查询1000条数据
	
	//结束时间
	private Date conditionTime;
	//当前页
	private int currentPage;
	//每页大小
	private int pageSize;
	//总记录数
	private int totalCount;
	// 开始索引
	private int startIndex;
	//总页数
	private int totalPage;
	
	public DataQuereyCondition(Date conditionTime) {
		setConditionTime(conditionTime);
		this.currentPage = DEFULT_PAGENUM;
		this.pageSize = DEFULT_PAGESIZE;
		this.startIndex = (currentPage - 1) * pageSize;
	}
	
	public DataQuereyCondition(int currentPage, int pageSize) {
		setCurrentPage(currentPage);
		setPageSize(pageSize);
		this.startIndex = (currentPage - 1) * pageSize;
	}

	
	public Date getConditionTime() {
		return conditionTime;
	}

	public void setConditionTime(Date conditionTime) {
		this.conditionTime = conditionTime;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		if (currentPage<1) {
			throw new IllegalArgumentException("currentPage参数必须大于等于1!");
		}
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		if (pageSize<1) {
			throw new IllegalArgumentException("pageSize参数必须大于等于1!");
		}
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	
	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}
	
	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public void initTotalPage(int totalRecord){
		// totalPage 总页数
		if (totalRecord % pageSize == 0) {
			// 说明整除，正好每页显示pageSize条数据，没有多余一页要显示少于pageSize条数据的
			this.totalPage = totalRecord / pageSize;
		} else {
			// 不整除，就要在加一页，来显示多余的数据。
			this.totalPage = totalRecord / pageSize + 1;
		}
	}

	
	public boolean nextExecut(){
		return this.totalPage > this.currentPage;
	}
	
	public DataQuereyCondition nextPageCount(){
		if (this.currentPage > this.totalPage) {
			throw new IllegalArgumentException("分页数大于总页数！");
		}
		this.currentPage = this.currentPage +1;
		this.startIndex = (currentPage - 1) * pageSize;
		return this;
	}
}
